<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>071-HTML5-Web存储-localStorage对象-实例1</title>
    <!-- 下面的实例展示了用户点击按钮的次数。 -->
    <!-- 代码中的字符串值转换为数字类型:  -->
    <script>
        function clickCounter() {
            if (typeof (Storage) !== "undefined") {
                if (localStorage.clickcount) {
                    localStorage.clickcount = Number(localStorage.clickcount) + 1;
                }
                else {
                    localStorage.clickcount = 1;
                }
                document.getElementById("result").innerHTML = " 你已经点击了按钮 " + localStorage.clickcount + " 次 ";
            }
            else {
                document.getElementById("result").innerHTML = "对不起，您的浏览器不支持 web 存储。";
            }
        }
    </script>
</head>

<body>
    <p><button onclick="clickCounter()" type="button">点我！</button></p>
    <div id="result"></div>
    <p>点击该按钮查看计数器的增加。</p>
    <p>关闭浏览器选项卡(或窗口),重新打开此页面,计数器将继续计数(不是重置)。</p>
</body>

</html>